﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Caching;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.BL;
using VINETLIFE.DO;

namespace VINETLIFE.Module
{
    public partial class ucVnSlidePartner : System.Web.UI.UserControl
    {
        private Cache cache = HttpContext.Current.Cache;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rptImageDataSource();
                CheckPage();
            }
        }
        protected void CheckPage()
        {
            List<string> pageToHide = new List<string>();
            sysConfigDO objConfig = new sysConfigBL().Select(new sysConfigDO { ConfigID = 38 });
            if (objConfig != null)
            {
                if (!string.IsNullOrEmpty(objConfig.ConfigValue))
                {
                    if (Ultility.IsJson(objConfig.ConfigValue))
                    {
                        JavaScriptSerializer objJSSerializer = new JavaScriptSerializer();
                        pageToHide = objJSSerializer.Deserialize<List<string>>(objConfig.ConfigValue);

                        string absolutePath = Request.Url.AbsolutePath;
                        string pathToCompare = "";
                        try
                        {
                         pathToCompare =   absolutePath.Substring(absolutePath.IndexOf("/") + 1, absolutePath.LastIndexOf("/") - 1);
                        }
                        catch
                        {
                            pathToCompare = "";
                        }
                        if (!pathToCompare.Equals(""))
                        {
                            if (pageToHide.Contains(pathToCompare))
                            {
                                divSlidePartnerWrap.Visible = false;
                            }
                        }
                    }
                }
            }
        }
        protected void rptImageDataSource()
        {
            if (cache["SlidePartner"] == null)
            {
                DataTable dtCache = new SlideBL().SelectByCategoryID(2);// new DataView(new cmsDoiTacBL().SelectAll()).ToTable();
                if (dtCache != null)
                    cache.Insert("SlidePartner", dtCache, null, DateTime.Now.AddSeconds(150), TimeSpan.Zero);
            }
            rptImage.DataSource = (DataTable)cache["SlidePartner"];
            rptImage.DataBind();
        }
        public string FriendlyUrl(string s)
        {
            return Ultility.Change_AV(s);
        }
    }
    public class PageToHide
    {
        public string page { get; set; }
    }
}